let api = [];
const apiDocListSize = 1
api.push({
    name: 'default',
    order: '1',
    list: []
})
api[0].list.push({
    alias: 'ArthasOutPutController',
    order: '1',
    link: 'arthas火焰图浏览',
    desc: 'arthas火焰图浏览',
    list: []
})
api[0].list[0].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/arthas-output.html',
    desc: 'arthas火焰图列表',
});
api[0].list[0].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/arthas-output/{fileName}',
    desc: '预览火焰图',
});
api[0].list.push({
    alias: 'AsyncController',
    order: '2',
    link: '异步controller',
    desc: '异步Controller',
    list: []
})
api[0].list[1].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/testCallable',
    desc: '测试callable',
});
api[0].list[1].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/asyncNoReturn',
    desc: '异步无返回',
});
api[0].list[1].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/asyncReturn',
    desc: '测试异步返回',
});
api[0].list[1].list.push({
    order: '4',
    deprecated: 'false',
    url: '/benchmark/asyncCountDownLatchWait',
    desc: 'CountDownLatch等待',
});
api[0].list[1].list.push({
    order: '5',
    deprecated: 'false',
    url: '/benchmark/asyncData',
    desc: '异步同步数据',
});
api[0].list[1].list.push({
    order: '6',
    deprecated: 'false',
    url: '/benchmark/callable',
    desc: '调用callable异步执行',
});
api[0].list.push({
    alias: 'BlockController',
    order: '3',
    link: '阻塞任务测试',
    desc: '阻塞任务测试',
    list: []
})
api[0].list[2].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/block',
    desc: '阻塞任务测试',
});
api[0].list.push({
    alias: 'ConcurrentHashMapController',
    order: '4',
    link: 'concurrenthashmap用例',
    desc: 'ConcurrentHashMap用例',
    list: []
})
api[0].list[3].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/concurrentHashMap/wrong',
    desc: '错误用例',
});
api[0].list[3].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/concurrentHashMap/right',
    desc: '正确用例',
});
api[0].list.push({
    alias: 'CpuController',
    order: '5',
    link: '获取cpu信息',
    desc: '获取cpu信息',
    list: []
})
api[0].list[4].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/cpu/cores',
    desc: '获取cpu数',
});
api[0].list[4].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/cpu/startHighMock',
    desc: 'cpu占用100%模拟',
});
api[0].list[4].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/cpu/stopHighMock',
    desc: '停止cpu占用100%模拟',
});
api[0].list.push({
    alias: 'DeadLockController',
    order: '6',
    link: '死锁测试',
    desc: '死锁测试',
    list: []
})
api[0].list[5].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/deadLock',
    desc: '死锁',
});
api[0].list.push({
    alias: 'DeferredResultController',
    order: '7',
    link: 'deferredresult用例',
    desc: 'DeferredResult用例',
    list: []
})
api[0].list[6].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/deferredResult/okHttp3/asyncGet',
    desc: 'okHttp3异步网络请求',
});
api[0].list[6].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/deferredResult/async-deferredresult',
    desc: 'deferred响应',
});
api[0].list[6].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/deferredResult/timeout',
    desc: 'deferred响应超时',
});
api[0].list[6].list.push({
    order: '4',
    deprecated: 'false',
    url: '/benchmark/deferredResult/findUserList',
    desc: '异步获取数据合并返回',
});
api[0].list.push({
    alias: 'ExceptionTestController',
    order: '8',
    link: '异常测试',
    desc: '异常测试',
    list: []
})
api[0].list[7].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/exp',
    desc: '抛异常测试',
});
api[0].list.push({
    alias: 'HttpTestController',
    order: '9',
    link: 'http请求用例',
    desc: 'http请求用例',
    list: []
})
api[0].list[8].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/testHttps',
    desc: 'https方式访问',
});
api[0].list[8].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/testHttp',
    desc: '访问内部接口',
});
api[0].list[8].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/svc/{svc}',
    desc: '访问k8s service',
});
api[0].list.push({
    alias: 'IndexController',
    order: '10',
    link: '基本接口访问',
    desc: '基本接口访问',
    list: []
})
api[0].list[9].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/',
    desc: '默认访问根路径',
});
api[0].list.push({
    alias: 'IpController',
    order: '11',
    link: '获取ip地址',
    desc: '获取ip地址',
    list: []
})
api[0].list[10].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/ip/',
    desc: '获取本机ip地址',
});
api[0].list[10].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/ip/v4/all',
    desc: '获取所有的ipv4地址',
});
api[0].list[10].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/ip/v4/{netInterface}',
    desc: '根据网卡获取ipv4地址',
});
api[0].list[10].list.push({
    order: '4',
    deprecated: 'false',
    url: '/benchmark/ip/v6/all',
    desc: '获取所有的ipv6地址',
});
api[0].list[10].list.push({
    order: '5',
    deprecated: 'false',
    url: '/benchmark/ip/v6/{netInterface}',
    desc: '根据网卡获取ipv6地址',
});
api[0].list.push({
    alias: 'LivenessSettingController',
    order: '12',
    link: 'springboot_2.3+存活探针测试',
    desc: 'SpringBoot 2.3+存活探针测试',
    list: []
})
api[0].list[11].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/liveness/correct',
    desc: '设置活探针为可用状态',
});
api[0].list[11].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/liveness/broken',
    desc: '设置存活探针设置为不可用状态',
});
api[0].list.push({
    alias: 'LogController',
    order: '13',
    link: '日志测试',
    desc: '日志测试',
    list: []
})
api[0].list[12].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/log',
    desc: '日志打印',
});
api[0].list.push({
    alias: 'LongProcessController',
    order: '14',
    link: '模拟延迟处理',
    desc: '模拟延迟处理',
    list: []
})
api[0].list[13].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/long-process/{delay}',
    desc: '延迟测试',
});
api[0].list[13].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/delay/{delay}',
    desc: '延迟后返回延迟时间',
});
api[0].list.push({
    alias: 'MemoryOutController',
    order: '15',
    link: 'jvm各内存溢出测试',
    desc: 'jvm各内存溢出测试',
    list: []
})
api[0].list[14].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/memory/heapOut',
    desc: '堆内存溢出测试',
});
api[0].list[14].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/memory/directoryMemoryOut/{sleepTime}',
    desc: '启动直接内存占用溢出任务',
});
api[0].list[14].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/memory/directoryMemoryOutStop',
    desc: '停止直接内存占用溢出任务',
});
api[0].list.push({
    alias: 'ReadinessSettingController',
    order: '16',
    link: 'springboot_2.3+就绪探针测试',
    desc: 'SpringBoot 2.3+就绪探针测试',
    list: []
})
api[0].list[15].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/readiness/accepting',
    desc: '设置就绪探针为就绪状态',
});
api[0].list[15].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/readiness/refuse',
    desc: '设置就绪探针为拒绝状态',
});
api[0].list.push({
    alias: 'ThreadLocalController',
    order: '17',
    link: 'threadlocal使用测试',
    desc: 'ThreadLocal使用测试',
    list: []
})
api[0].list[16].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/threadLocal/wrong/{userId}',
    desc: 'ThreadLocal错误使用',
});
api[0].list[16].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/threadLocal/right/{userId}',
    desc: 'ThreadLocal正例使用',
});
api[0].list.push({
    alias: 'TimeController',
    order: '18',
    link: '检验服务器时间',
    desc: '检验服务器时间',
    list: []
})
api[0].list[17].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/time',
    desc: '获取时间',
});
api[0].list.push({
    alias: 'UserController',
    order: '19',
    link: '用户操作接口',
    desc: '用户操作接口',
    list: []
})
api[0].list[18].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/query',
    desc: '根据id用户信息',
});
api[0].list[18].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/tracing/{traceId}',
    desc: '链路原样包返回',
});
api[0].list[18].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/tracing/{traceId}/{delay}',
    desc: '链路原样包返回',
});
api[0].list.push({
    alias: 'WebAsyncTaskController',
    order: '20',
    link: 'webasynctask',
    desc: 'WebAsyncTask',
    list: []
})
api[0].list[19].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/webAsyncTask/callable',
    desc: 'webAsyncTask返回执行结果',
});
api[0].list[19].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/webAsyncTask/completion',
    desc: 'WebAsyncTask  Completion处理',
});
api[0].list[19].list.push({
    order: '3',
    deprecated: 'false',
    url: '/benchmark/webAsyncTask/exception',
    desc: 'WebAsyncTask  Exception处理',
});
api[0].list[19].list.push({
    order: '4',
    deprecated: 'false',
    url: '/benchmark/webAsyncTask/timeout',
    desc: 'WebAsyncTask超时测试',
});
api[0].list.push({
    alias: 'XssController',
    order: '21',
    link: 'xss处理',
    desc: 'Xss处理',
    list: []
})
api[0].list[20].list.push({
    order: '1',
    deprecated: 'false',
    url: '/benchmark/xss/json',
    desc: 'xss处理json',
});
api[0].list[20].list.push({
    order: '2',
    deprecated: 'false',
    url: '/benchmark/xss/normal',
    desc: '普通表单xss',
});
api[0].list.push({
    alias: 'error',
    order: '22',
    link: 'error_code_list',
    desc: '错误码列表',
    list: []
})
api[0].list.push({
    alias: 'dict',
    order: '23',
    link: 'dict_list',
    desc: '数据字典',
    list: []
})
api[0].list[22].list.push({
    order: '1',
    deprecated: 'false',
    url: '',
    desc: 'http状态码字典',
});
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
        const search = document.getElementById('search');
        const searchValue = search.value.toLocaleLowerCase();

        let searchGroup = [];
        for (let i = 0; i < api.length; i++) {

            let apiGroup = api[i];

            let searchArr = [];
            for (let i = 0; i < apiGroup.list.length; i++) {
                let apiData = apiGroup.list[i];
                const desc = apiData.desc;
                if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                    searchArr.push({
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        list: apiData.list
                    });
                } else {
                    let methodList = apiData.list || [];
                    let methodListTemp = [];
                    for (let j = 0; j < methodList.length; j++) {
                        const methodData = methodList[j];
                        const methodDesc = methodData.desc;
                        if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                            methodListTemp.push(methodData);
                            break;
                        }
                    }
                    if (methodListTemp.length > 0) {
                        const data = {
                            order: apiData.order,
                            desc: apiData.desc,
                            link: apiData.link,
                            list: methodListTemp
                        };
                        searchArr.push(data);
                    }
                }
            }
            if (apiGroup.name.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchGroup.push({
                    name: apiGroup.name,
                    order: apiGroup.order,
                    list: searchArr
                });
                continue;
            }
            if (searchArr.length === 0) {
                continue;
            }
            searchGroup.push({
                name: apiGroup.name,
                order: apiGroup.order,
                list: searchArr
            });
        }
        let html;
        if (searchValue == '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchGroup,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiGroups, liClass, display) {
    let html = "";
    let doc;
    if (apiGroups.length > 0) {
         if (apiDocListSize == 1) {
            let apiData = apiGroups[0].list;
            for (let j = 0; j < apiData.length; j++) {
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                html += '<ul class="sectlevel2" style="'+display+'">';
                doc = apiData[j].list;
                for (let m = 0; m < doc.length; m++) {
                    let spanString;
                    if (doc[m].deprecated == 'true') {
                        spanString='<span class="line-through">';
                    } else {
                        spanString='<span>';
                    }
                    html += '<li><a href="#_1_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                }
                html += '</ul>';
                html += '</li>';
            }
        } else {
            for (let i = 0; i < apiGroups.length; i++) {
                let apiGroup = apiGroups[i];
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiGroup.name + '">' + apiGroup.order + '.&nbsp;' + apiGroup.name + '</a>';
                html += '<ul class="sectlevel1">';

                let apiData = apiGroup.list;
                for (let j = 0; j < apiData.length; j++) {
                    html += '<li class="'+liClass+'">';
                    html += '<a class="dd" href="#_'+apiGroup.order+'_'+ apiData[j].order + '_'+ apiData[j].link + '">' +apiGroup.order+'.'+ apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                    html += '<ul class="sectlevel2" style="'+display+'">';
                    doc = apiData[j].list;
                    for (let m = 0; m < doc.length; m++) {
                       let spanString;
                       if (doc[m].deprecated == 'true') {
                           spanString='<span class="line-through">';
                       } else {
                           spanString='<span>';
                       }
                       html += '<li><a href="#_'+apiGroup.order+'_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">'+apiGroup.order+'.' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                   }
                    html += '</ul>';
                    html += '</li>';
                }

                html += '</ul>';
                html += '</li>';
            }
        }
    }
    return html;
}